﻿using System.Security.Principal;
using System.Web;
using StockholmsStad.Web.UI.Class.Interfaces;

namespace StockholmsStad.Web.UI.Class.Utilities
{
    /// <summary>
    /// Adapter för HttpContext. Objektet användas sedan
    /// i Model-klasser jobba mot content.
    /// Se http://en.wikipedia.org/wiki/Adapter_pattern
    /// </summary>
    public class HttpContextAdapter : IHttpContextAdapter
    {
        private readonly HttpContext _context;

        ///<summary>
        /// Spapar en adapter för IHttpContextAdapter
        ///</summary>
        ///<param name="context"></param>
        public HttpContextAdapter(HttpContext context)
        {
            _context = context;
        }

        /// <summary>
        /// true if the user was authenticated; otherwise, false.
        /// </summary>
        public bool IsAuthenticated()
        {
            return _context.User.Identity.IsAuthenticated;
        }

        ///<summary>
        /// Returnerar användarnamnet
        ///</summary>
        ///<returns></returns>
        public string GetUsername()
        {
            return _context.User.Identity.Name;
        }
    }
}